package it.polimi.TravelDream;

import java.io.Serializable;

import javax.persistence.*;
import javax.resource.spi.AuthenticationMechanism;

import java.util.Date;
import java.util.List;


/**
 * The persistent class for the flight database table.
 * 
 */
@Entity
@NamedQueries({
	@NamedQuery(name="Flight.findAll", query="SELECT f FROM Flight f"),
@NamedQuery(name="Flight.searchQuery", query="SELECT f FROM Flight f WHERE f.arrLocation LIKE :param1 and f.depLocation LIKE :param2 and f.date_Time >= :param3")
})
public class Flight implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private int id;

	@Temporal(TemporalType.DATE)
	private Date addDate;

	private String arrAirport;

	private String arrLocation;
	
	private int capacity;

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="`Date&Time`")
	private Date date_Time;

	private String depAirport;

	private String depLocation;

	private String description;

	private String flag;

	private int price;

	//bi-directional many-to-one association to Basepackage
	@OneToMany(mappedBy="flight1")
	private List<Basepackage> basepackages1;

	//bi-directional many-to-one association to Basepackage
	@OneToMany(mappedBy="flight2")
	private List<Basepackage> basepackages2;

	//bi-directional many-to-one association to User
	@ManyToOne
	@JoinColumn(name="AddedBy")
	private User user;

	//bi-directional many-to-one association to Savedpackage
	@OneToMany(mappedBy="flight1")
	private List<Savedpackage> savedpackages1;

	//bi-directional many-to-one association to Savedpackage
	@OneToMany(mappedBy="flight2")
	private List<Savedpackage> savedpackages2;

	public Flight() {
		super();
	}
	
	public Flight(FlightDTO flight) {
		this.id = flight.getId();
		this.addDate = new Date();
		this.arrAirport = flight.getArrAirport();
		this.arrLocation = flight.getArrLocation();
		this.capacity = flight.getCapacity();
		this.date_Time = flight.getDate_Time();
		this.depAirport = flight.getDepAirport();
		this.depLocation = flight.getDepLocation();
		this.flag = flight.getFlag();
		this.price = flight.getPrice();
		this.description = flight.getDescription();
	}

	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public Date getAddDate() {
		return this.addDate;
	}

	public void setAddDate(Date addDate) {
		this.addDate = addDate;
	}

	public String getArrAirport() {
		return this.arrAirport;
	}

	public void setArrAirport(String arrAirport) {
		this.arrAirport = arrAirport;
	}

	public String getArrLocation() {
		return this.arrLocation;
	}

	public void setArrLocation(String arrLocation) {
		this.arrLocation = arrLocation;
	}

	public int getCapacity() {
		return this.capacity;
	}

	public void setCapacity(int capacity) {
		this.capacity = capacity;
	}

	public Date getDate_Time() {
		return this.date_Time;
	}

	public void setDate_Time(Date date_Time) {
		this.date_Time = date_Time;
	}

	public String getDepAirport() {
		return this.depAirport;
	}

	public void setDepAirport(String depAirport) {
		this.depAirport = depAirport;
	}

	public String getDepLocation() {
		return this.depLocation;
	}

	public void setDepLocation(String depLocation) {
		this.depLocation = depLocation;
	}

	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getFlag() {
		return this.flag;
	}

	public void setFlag(String flag) {
		this.flag = flag;
	}

	public int getPrice() {
		return this.price;
	}

	public void setPrice(int price) {
		this.price = price;
	}

	public List<Basepackage> getBasepackages1() {
		return this.basepackages1;
	}

	public void setBasepackages1(List<Basepackage> basepackages1) {
		this.basepackages1 = basepackages1;
	}

	public Basepackage addBasepackages1(Basepackage basepackages1) {
		getBasepackages1().add(basepackages1);
		basepackages1.setFlight1(this);

		return basepackages1;
	}

	public Basepackage removeBasepackages1(Basepackage basepackages1) {
		getBasepackages1().remove(basepackages1);
		basepackages1.setFlight1(null);

		return basepackages1;
	}

	public List<Basepackage> getBasepackages2() {
		return this.basepackages2;
	}

	public void setBasepackages2(List<Basepackage> basepackages2) {
		this.basepackages2 = basepackages2;
	}

	public Basepackage addBasepackages2(Basepackage basepackages2) {
		getBasepackages2().add(basepackages2);
		basepackages2.setFlight2(this);

		return basepackages2;
	}

	public Basepackage removeBasepackages2(Basepackage basepackages2) {
		getBasepackages2().remove(basepackages2);
		basepackages2.setFlight2(null);

		return basepackages2;
	}

	public User getUser() {
		return this.user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public List<Savedpackage> getSavedpackages1() {
		return this.savedpackages1;
	}

	public void setSavedpackages1(List<Savedpackage> savedpackages1) {
		this.savedpackages1 = savedpackages1;
	}

	public Savedpackage addSavedpackages1(Savedpackage savedpackages1) {
		getSavedpackages1().add(savedpackages1);
		savedpackages1.setFlight1(this);

		return savedpackages1;
	}

	public Savedpackage removeSavedpackages1(Savedpackage savedpackages1) {
		getSavedpackages1().remove(savedpackages1);
		savedpackages1.setFlight1(null);

		return savedpackages1;
	}

	public List<Savedpackage> getSavedpackages2() {
		return this.savedpackages2;
	}

	public void setSavedpackages2(List<Savedpackage> savedpackages2) {
		this.savedpackages2 = savedpackages2;
	}

	public Savedpackage addSavedpackages2(Savedpackage savedpackages2) {
		getSavedpackages2().add(savedpackages2);
		savedpackages2.setFlight2(this);

		return savedpackages2;
	}

	public Savedpackage removeSavedpackages2(Savedpackage savedpackages2) {
		getSavedpackages2().remove(savedpackages2);
		savedpackages2.setFlight2(null);

		return savedpackages2;
	}

}